package com.zhongyu.service.impl;


import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zhongyu.mapper.ProviderMapper;
import com.zhongyu.pojo.Provider;
import com.zhongyu.service.ProviderService;
import com.zhongyu.vo.PageResult;
import com.zhongyu.vo.ProviderVo;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import javax.annotation.Resource;
import java.util.List;

@Service("ProviderService")
public class ProviderServicelmpl extends ServiceImpl<ProviderMapper, Provider> implements ProviderService {
    @Resource
    private ProviderMapper providerMapper;

    @Override
    public PageResult searchAll(Integer pageNo, Integer pageSize, ProviderVo providerVo) {
        LambdaQueryWrapper<Provider> wrapper= Wrappers.<Provider>lambdaQuery();
        wrapper.like(!StringUtils.isEmpty(providerVo.getProName()),Provider::getProName,providerVo.getProName())
                .like(!StringUtils.isEmpty(providerVo.getProAddress()),Provider::getProAddress,providerVo.getProAddress())
                .like(!StringUtils.isEmpty(providerVo.getProContact()),Provider::getProContact,providerVo.getProContact())
                .like(!StringUtils.isEmpty(providerVo.getProPhone()),Provider::getProPhone,providerVo.getProPhone())
                        .like(!StringUtils.isEmpty(providerVo.getProFax()),Provider::getProFax,providerVo.getProFax());
        Page page=new Page(pageNo,pageSize);
        List<Provider> list=baseMapper.findAll(page,wrapper);
        return new PageResult(list,page.getTotal());
    }

    @Override
    public List<Provider> searchAll() {
        return providerMapper.selectList(null);
    }


    @Override
    public void add(Provider provider) {

        providerMapper.insert(provider);
    }

    @Override
    public void del(Integer id) {

        providerMapper.deleteById(id);
    }

    @Override
    public void update(Provider provider) {
        providerMapper.updateById(provider);
    }
}
